int ret = -1010;
int  dfs(TreeNode* root)
{
    if (root == nullptr)
        return 0;
    int l = max(dfs(root->left), 0);
    int r = max(dfs(root->right), 0);
    ret = max(ret, l + r + root->val);
    return max(l, r) + root->val;
}
int maxPathSum(TreeNode* root) {
    dfs(root);
    return ret;
    // write code here


}